package cn.edu.nuc.onlinestore.network.server;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Map;

import cn.edu.nuc.onlinestore.model.Goods;
import cn.edu.nuc.onlinestore.vo.Cart;
import cn.edu.nuc.onlinestore.vo.Massage;

public class TCPClient {
	static Socket socket;
	private Massage msg;
	public TCPClient(String ip,int dk){
		try {
			socket=new Socket(ip,dk);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void sendOptmessage(Massage msg){
		System.out.println("获得了"+msg.getOpt()+"操作");
		ObjectStream.output(msg, socket);
		this.msg=ObjectStream.input(socket);
		System.out.println("发送了"+msg.getOpt()+"操作");
	}
	public int  getNum(){
		return msg.getCode();
	}
	public String  getResult(){
		return msg.getOpt();
	}
	public String  getmsg(){
		System.out.println("--"+msg.getMsg());
		return msg.getMsg();
	}
	@SuppressWarnings("unchecked")
	public Map<String,Goods> getMap(){
		return (Map<String,Goods>)msg.getClasss();
	}
	public Cart getTotal(){
		return (Cart)msg.getClasss();
	}
	public Goods getGoods(){
		return (Goods)msg.getClasss();
	}
	
	//测试
	/*public static void main(String args[]){
		new TCPClient("127.0.0.1",8000);
		Massage msg=new Massage(0,"h","as",null);
		ObjectStream.output(msg,socket);
		getmsg().getResule();
		getmsg().getMasg();
	}*/
}
